<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4684 2010-08-16 08:44:14Z jam-gate.vn $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('customer_list_page_title'));

$this->headLink()
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.core.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.resizable.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.dialog.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.core.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.draggable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.droppable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.resizable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.dialog.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
	<div class="grid_11 alpha"><span><?php echo $this->translator('customer_list_breadcrumb'); ?></span></div>
	<div class="grid_1 omega"><?php echo $this->languageSwitcher('flag', str_repeat('&nbsp;', 2)); ?></div>		
</div>
<?php if (count($this->customers) > 0) : ?>
<!--  Filter customer -->
<div class="grid_12 t_a_top t_a_bottom">
	<form  action="" method="POST">
		<button type="submit"><span><?php echo $this->translator("customer_customer_filter");?></span></button>			
	</form>
</div>
<?php endif; ?>
<div class="grid_12">
	<div class="grid_9 alpha">
		<u>
			<?php if (count($this->customers) == 0) : ?>
			<?php echo $this->translator('customer_list_not_found'); ?>
			<?php else : ?>
			<?php echo $this->translator('customer_list_guide'); ?>
			<?php endif; ?>
		</u>
	</div>
	
	<div class="grid_3 omega">
		<div class="t_a_right">	
			<a href="<?php echo $this->url(array(), 'customer_customer_add'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('customer_add_breadcrumb'); ?></span></a>
		</div>
	</div>
</div>
<?php if (count($this->customers) > 0) : ?>
	<div class="grid_12 t_a_top t_a_bottom">
		<!-- List customers-->
		<table id="customerTable" class="t_a_ui_table" style="width:100%;">
			<thead>
				<tr>
					<th width="150px"><?php echo $this->translator('customer_customer_name'); ?></th>
					<th><?php echo $this->translator("customer_customer_sex");?></th>
					<th><?php echo $this->translator("customer_customer_tel");?></th>
					<th><?php echo $this->translator("customer_customer_address");?></th>
					<th><?php echo $this->translator("customer_customer_birthday");?></th>
					<th><?php echo $this->translator("customer_customer_amount_time");?></th>
					<th><?php echo $this->translator("customer_customer_last_time");?></th>
					<th width="80px"><?php echo $this->translator('customer_customer_id'); ?></th>
				</tr>
			</thead>
			
			<tbody>
				<?php foreach ($this->customers as $customer) : ?>			
				<tr id="row_id_<?php echo $customer->id; ?>">
					<td>
						<span>
							<?php echo $customer->name;?>
						</span>
						<span class="t_a_ui_helper_action" style="display: none; padding-left: 20px">
								<?php if ($this->allow('edit')) : ?>
								<a href="<?php echo $this->url(array('customer_id' => $customer->id), 'customer_customer_edit'); ?>"><?php echo $this->translator('customer_list_action_edit'); ?></a> | 
								<?php endif; ?>							
								<?php if ($this->allow('delete')) : ?>
								<a href="javascript: void(0);" class="deleteAction" rel="<?php echo $customer->id; ?>"><?php echo $this->translator('customer_list_action_delete'); ?></a>
								<?php endif; ?>
						</span>
					</td>
					<td>
						<span><?php echo $this->translator("core_sex_".$customer->sex,"core");?></span>
					</td>
					<td>
						<span><?php echo $customer->tel;?></span>
					</td>
					<td>
						<span><?php echo $customer->address;?></span>
					</td>
					<td>
						<span><?php echo $customer->birthday;?></span>
					</td>
					<td>
						<span><?php echo $customer->amount_time;?></span>
					</td>
					<td>
						<span><?php echo $customer->last_time;?></span>
					</td>
					<td><?php echo $customer->id; ?>
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
	<div class="grid_12 t_a_bottom t_a_paginator">
	    <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
	</div>
<?php endif;?>
<div id="messageDialog"></div>

<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
	/**
	 * Data list hover handler
	 */
	$('#customerTable tr').hover(function() {
		$(this).find('.t_a_ui_helper_action').show();
	}, function() {
		$(this).find('.t_a_ui_helper_action').hide();
	});
	
	<?php if ($this->allow('delete')) : ?>
	$('a.deleteAction').click(function() {
		var self = this;
		$('#confirmDialog').html('<?php echo addslashes($this->translator('customer_list_action_delete_confirm')); ?>')
			.dialog({
				title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
				dialogClass: 't_a_ui_dialog',
				modal: true,
				closeOnEscape: false,
				resizable: false,
				open: function(event, ui) {
					$('.ui-dialog-titlebar-close').hide();
					$(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
				},
				buttons: {
					'<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
						$(this).dialog('destroy');
					},
					'<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
						$(this).dialog('destroy');
						$(self).html('').addClass('t_a_ui_helper_loading');
						var id = $(self).attr('rel');
						$.ajaxq('customer_list', {
							type: 'POST',
							url: '<?php echo $this->url(array(), 'customer_customer_delete'); ?>',
							data: { id: id },
							success: function(response) {
								if ('RESULT_OK' == response) {
									$('#row_id_' + id).fadeOut('slow');
									window.location = '<?php echo $this->url(array(), 'customer_customer_list'); ?>';
								}
							}
						});
					}
				}
			});
	});
	<?php endif; ?>
});
</script>